D = Device(MODBUS)
W = Writing functions
The DW13Modbus function manages the interchange via MODBUS protocoll among any apparatus that acts as a Master and Qmove (Slave).
In particular the function sorts an array (named “aswBuffer” in the below example) that must be declared by the user and passed to the function. This array will mirror faithfully the Modbus address table. The number of elements in this array must be at least equal to the number of the highest address of your device (for example, if the highest address between the variables you want to exchange is 600, the minimum size of the array must be of 600 items).
For the use of the function is mandatory set the 2 value on the “mode” parameter of the Modbus device passed to the function.
DW13Modbus (Modbus, aswBuffer, slrdelay, gbWriteRead, sbError)
Parameters:
| IN/OUT | VARIABLE TYPE | EXAMPLE NAME | DIM | |
|---|---|---|---|---|
| IN | INTDEVICE | Modbus | - | Mnemonic name of MODBUS devices used |
| IN | ARRSYS / ARRGBL | aswBuffer | W | Address Buffer |
| IN | SYSTEM | slrdelay | L | It is the time to wait before transmitting the reply. |
| OUT | GLOBAL | gbWriteRead | B | Variable that indicates the read or write request from the Master. 0 = no request 1 = reading 2 = writing |
| OUT | SYSTEM | sbError | B | Variable containing the error code |
After calling the function if there are any errors the error variable having the following values:
0 - No error
1 - “Mode” parameter not set correctly (<> 2)
2 - Address exceeds the Buffer size
3 - The number of word be written exceeds the Buffer size
4 - Address ⇐ 0
5 - Number of word writing ⇐ 0
(Without the “gbWriteRead” flag address)
TASK_00
Modbus:idcard = 1
Modbus:mode=2
Modbus:prot=1
Modbus:wider=0
Modbus:brate=38400
Modbus:stopb=1
Modbus:par=0
Modbus:toutsyc=100
OPENCOM Modbus
WAIT Modbus:st_opencom
slrdelay = 0
MAIN:
DW13Modbus (Modbus, aswBuffer, slrdelay, gbWriteRead, sbError)
IF NOT sbError
aswBuffer[20] = swPippo
aswBuffer[21] = swPluto
swMinnie = aswBuffer[30]
ELSE
gbMessaggio = sbError ;Variable to shown the error message
ENDIF
END
(With the “gbWriteRead” flag address)
TASK_00
Modbus:idcard = 1
Modbus:mode=2
Modbus:prot=1
Modbus:wider=0
Modbus:brate=38400
Modbus:stopb=1
Modbus:par=0
Modbus:toutsyc=100
OPENCOM Modbus
WAIT Modbus:st_opencom
slrdelay = 0
MAIN:
DW13Modbus (Modbus, aswBuffer, slrdelay, gbWriteRead, sbError)
IF NOT sbError
IF (gbWriteRead EQ 1)
;-- Reading Master ---------
aswBuffer[20] = swPippo
aswBuffer[21] = swPluto
ENDIF
IF (gbWriteRead EQ 2)
;-- Writing Master ---------
swPippo = aswBuffer[20]
swPluto = aswBuffer[21]
ENDIF
ELSE
gbMessaggio = sbError ;Variable to shown the error message
ENDIF
END
The restriction on the number of variables that you can exchange is as follows